package cn.stylefeng.guns.modular.shi.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.shi.entity.TaoHelp;
import cn.stylefeng.guns.modular.shi.mapper.TaoHelpMapper;
import cn.stylefeng.guns.modular.shi.model.params.TaoHelpParam;
import cn.stylefeng.guns.modular.shi.model.result.TaoHelpResult;
import  cn.stylefeng.guns.modular.shi.service.TaoHelpService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 帮助中心 服务实现类
 * </p>
 *
 * @author shiboshi
 * @since 2019-10-22
 */
@Service
public class TaoHelpServiceImpl extends ServiceImpl<TaoHelpMapper, TaoHelp> implements TaoHelpService {

    @Autowired
    private TaoHelpMapper taoHelpMapper;


    @Override
    public void add(TaoHelpParam param){
        TaoHelp entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TaoHelpParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TaoHelpParam param){
        TaoHelp oldEntity = getOldEntity(param);
        TaoHelp newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TaoHelpResult findBySpec(TaoHelpParam param){
        return null;
    }

    @Override
    public List<TaoHelpResult> findListBySpec(TaoHelpParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(TaoHelpParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TaoHelpParam param){
        return null;
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TaoHelp getOldEntity(TaoHelpParam param) {
        return this.getById(getKey(param));
    }

    private TaoHelp getEntity(TaoHelpParam param) {
        TaoHelp entity = new TaoHelp();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }



    /**
     * 查询做大值
     */
    public int idMax(){
        return taoHelpMapper.idMax();
    }


    /**
     * 新增接口
     */
    public void addTaoHelp(TaoHelpParam taoHelpParam){
        this.taoHelpMapper.addTaoHelp(taoHelpParam);
    }


    /**
     * 删除接口
     */
    public void deleteTaoHelp(@Param("id") Integer id){
        this.taoHelpMapper.deleteTaoHelp(id);
    }


    /**
     * 查看详情接口
     */
    public TaoHelp QueryHelp(@Param("id") String id){
        return taoHelpMapper.QueryHelp(id);
    }


    /**
     * 修改数据接口
     */
    public void updateHelp(TaoHelpParam taoHelpParam){
        this.taoHelpMapper.updateHelp(taoHelpParam);
    }


    /**
     * 修改图片
     */
    @Override
    public void updateImges(TaoHelpParam taoHelpParam) {
        taoHelpMapper.updateImges(taoHelpParam);
    }


}
